var ValidateRole = function () {
	return {
		init:function() {
			validator=$('.role-form').validate({
				errorElement: 'span', //default input error message container
				errorClass: 'help-block', // default input error message class
				focusInvalid: false, // do not focus the last invalid input
				rules: {
					roleName: {
						required: true,
						remote:{  
							type: "post",  
							url: ajaxUrl,  
							data: {  
								roleName: function() {  
									return $("#roleName").val();  
								},
								ajax:"checkRole"
							},  
							dataType: "json"
						}  
					},
					/* auth:{
						required: true
					} */
				},

				messages: {
					roleName: {
						required: "角色名不能为空。",
						remote:"角色名已占用！"
					},
					/* auth:{
						required: "请为角色分配权限！"
					} */
				},

				invalidHandler: function (event, validator) { //display error alert on form submit
					$('.alert-danger', $('.role-form')).show();
				},

				highlight: function (element) { // hightlight error inputs
					$(element)
						.closest('.form-group').addClass('has-error'); // set error class to the control group
				},

				success: function (label) {
					label.closest('.form-group').removeClass('has-error');
					label.remove();
				},

				errorPlacement: function (error, element) {
					error.insertAfter(element.closest('.input-icon'));
				},

				submitHandler: function (form) {
					
					$.ajax({
						url:ajaxUrl,
						type : "post",  
						dataType : "json",  
						data: $(".role-form").serialize(),  
						success : function(data) {
							if(data.status=='1'){
								layer.msg(data.info, 
									{icon: 1,time: 2000},
									function(){
										$('#responsive').modal('hide');
										oTable.fnReloadAjax();
									}
								);   	
							}else{
								layer.msg(data.info, 
									{icon: 2,time: 2000}
								);   
								return;
							}
						}  
					});           
				}
			});
			/* $('button').click(function(){
				validator.resetForm();
			}); */
			$('.role-form input').keypress(function (e) {
				if (e.which == 13) {
					if ($('.role-form').validate().form()) {
						$('.role-form').submit();
					}
					return false;
				}
			});
		}
    };
}();